package com.atguigu.juc.t12;

import java.util.concurrent.TimeUnit;

public class T1 {
    static volatile Integer num = 0;
    public static void main(String[] args) {
        new Thread(()->{
            while (num == 0){}
            System.out.println(Thread.currentThread().getName() + "接收到标记，准备击毙目标");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "把目标击毙");
        },"狙击手").start();

        new Thread(()->{
            System.out.println(Thread.currentThread().getName() + "发现目标开始标记目标");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            num = 1;
            System.out.println(Thread.currentThread().getName() + "标记目标");
        },"标记员").start();
    }
}
